package structuralPattern.decorator.example02;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

/**
 * 具体对象类
 */
public class BaseFileDataLoader extends DataLoder{

    private String filePath;

    public BaseFileDataLoader(String filePath) {
        this.filePath = filePath;
    }

    // 读
    @Override
    public String read() {
        String result = null;
        try {
            result = FileUtils.readFileToString(new File(filePath), "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    // 写
    @Override
    public void write(String str) {
        try {
            FileUtils.writeStringToFile(new File(filePath),str,"utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
